package com.k8.common.aop;

import com.k8.common.aop.internal.exception.JdkAspectException;

/*
 * 参数获取
 * 如果是接口匹配切面，也要添加进来
 * 1.避免pointCut重复匹配，重复添加
 * 2.参数匹配，如果当前切面要匹配的是可实例类，且具有接口，如果是通过接口进行调用（只有匹配上的方法是重写接口的才可能被接口调用），则可能出现接口method参数名和实现类参数名不同
 * 那么切面方法自动获取参数就会匹配不到，尽量保证重现的参数名和接口的一致
 * */
public class JdkAdvisedSupport extends AdvisedSupport {
    Class<?>[] targetInterfaces;

    public JdkAdvisedSupport(Object target, Class<?>... targetInterfaces) throws JdkAspectException {
        super(target);
        for (Class<?> targetInterface : targetInterfaces) {
            if (!targetInterface.isInterface()) {
                throw new JdkAspectException("target is not have interface");
            }
        }
        this.targetInterfaces = targetInterfaces;
    }

    public JdkAdvisedSupport(Object target) throws JdkAspectException {
        super(target);
        Class<?>[] interfaces = target.getClass().getInterfaces();
        if (interfaces.length == 0) throw new JdkAspectException("target is not have interface");
        this.targetInterfaces = interfaces;
    }

}
